#coding:utf8

import pandas as pd
from pyspark.sql import SparkSession
from pyspark.sql.types import StructType, StringType, IntegerType

# 构建DataFrame方法4:pandas转换成df
if __name__ == '__main__':
    # 构建SparkSession执行环境入口对象
    spark = SparkSession.builder.\
        appName("test").\
        master("local[*]").\
        getOrCreate()

    # pandas_df = pd.DataFrame({
    #     'id':[1,2,3],
    #     'name': ['张三', '李四', '王五'],
    #     'age':[10,20,30],
    # })

    pandas_df = pd.DataFrame([[1,'张三',10],[2,'李四',20],[3,'王五',30]],columns=['id','name','age'])
    print(pandas_df)

    df = spark.createDataFrame(pandas_df)

    df.show()
